// 150
package Leetcode_Second_Brush;

import java.util.Deque;
import java.util.LinkedList;

public class Solution150 {
    public int evalRPN(String[] tokens) {
        Deque<Integer> stack = new LinkedList<>();
        for (String s : tokens) {
            if ("+".equals(s)) {
                Integer pop1 = stack.pop();
                Integer pop2 = stack.pop();
                stack.push(pop2 + pop1);
            } else if ("-".equals(s)) {
                Integer pop1 = stack.pop();
                Integer pop2 = stack.pop();
                stack.push(pop2 - pop1);
            } else if ("*".equals(s)) {
                Integer pop1 = stack.pop();
                Integer pop2 = stack.pop();
                stack.push(pop2 * pop1);
            } else if ("/".equals(s)) {
                Integer pop1 = stack.pop();
                Integer pop2 = stack.pop();
                stack.push(pop2 / pop1);
            } else
                stack.push(Integer.valueOf(s));
        }
        return stack.peek();
    }
}
